<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/view/system/common/head.jsp"%>
<style>
 .labelTd{
    width:100px;
    text-align:right;
 }
</style>

<body>
	<table style="width: 100%; height: 100%">
		<tr>
			<td style="width: 50%; vertical-align: top;">
				<form id="form1" name="form1" method="post" action="">
					<div class="easyui-panel" title="参数信息">
						<table class="infoTable">
							<tr>
								<td class="labelTd">名称：</td>
								<td class="redText">${parameter.name}</td>
								<td class="labelTd">编码：</td>
								<td class="redText">${parameter.code}</td>
							</tr>
							<tr>
								<td class="labelTd">描述：</td>
								<td >${parameter.remark}</td>
							</tr>
						</table>
					</div>
					<table id="dataShow">
					</table>
				</form>
			</td>
			<td style="width: 50%; vertical-align: top;"><iframe
					id="parameterOperatorFrame" 
					style="width: 100%; height: 100%;border:0px;" scrolling="yes"> </iframe></td>
		</tr>
	</table>


</body>
<script type="text/javascript">

	$(document).ready(function() {
		setDataGridList();
	});

	//查询列表初始化
	function setDataGridList() {
		$('#dataShow').datagrid({
			url : 'parameter/getSubParameterList.action?parameterId=${parameter.id}',
			title : "参数项列表",
			fitColumns : true,
			nowrap : false,
			rownumbers : true,
			showFooter : false,
			pagination : false,
			striped : true,
			singleSelect : false,
			idField : 'id',
			frozenColumns : [ [ {
				field : 'ck',
				checkbox : true
			} ] ],
			tools : [ {
				iconCls : 'icon-reload',
				handler : function() {
					$('#dataShow').datagrid('reload');
				}
			} ],
			toolbar : [ {
				id : 'btnadd',
				text : '添加参数项',
				iconCls : 'icon-add',
				handler : function(rowData) {
					showAddParameter(rowData);
				}
			}, {
				id : 'btnremove',
				text : '删除',
				iconCls : 'icon-remove',
				handler : function() {
					removeBatch();
				}
			}, '-', {
				id : 'btnrefresh',
				text : '刷新',
				iconCls : 'icon-reload',
				handler : function() {
					$('#dataShow').datagrid('reload');
				}
			} ],
			columns : [ [ {
				field : 'id',
				width : 10,
				hidden : true,
				sortable : true
			}, {
				field : 'code',
				title : "编码",
				width : 10,
				sortable : true
			}, {
				field : 'name',
				title : "名称",
				width : 20,
				sortable : true
			}, {
				field : 'value',
				title : "值",
				width : 20,
				sortable : true
			} ] ],
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$('#dataShow').datagrid('unselectAll');
				$('#dataShow').datagrid('selectRow', rowIndex);
				createColumnMenu(rowData);
				$('#tmenu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});
	}

	var tmenu;
	function createColumnMenu(rowData) {
		if (tmenu != null) {
			$("#tmenu").remove();
		}
		var menuStr = '<div id="tmenu" style="width:135px;">';
		menuStr += '<div data-options="iconCls:\'icon-edit\'" id="update">修改</div>';
		
		menuStr += '</div>';
		tmenu = $(menuStr).appendTo('body');
		tmenu.menu({
			onClick : function(item) {
				if (item.id == 'update') {
					showParameterUpdate(rowData.id);
				}
			}
		});
	}

	function showAddParameter(rowData) {
		document.getElementById("parameterOperatorFrame").src = "view/goSubParameterAdd.action?parameterId="
				+ ${parameter.id};
	}
	function showParameterUpdate(rowId) {
		document.getElementById("parameterOperatorFrame").src = "view/goSubParameterUpdate.action?parameterId="
				+ rowId;
	}
	//批量删除
	function removeBatch() {
		var rows = $('#dataShow').datagrid('getSelections');
		if (rows.length == 0) {
			$.messager.alert('<s:text name="mes.message"/>', "请选择待操作的记录",
					'info');
		} else {
			$.messager.confirm('确认信息',
					"确定要删除选中的记录吗？（此操作无法恢复.）", function(r) {
						if (r) {
							var ids = getSelections(rows);
							delParameter(ids);			
						}
					});
		}
	}
	

	function delParameter(ids){
		$.axs("parameter/doParameterRemove.action", {'parameterIds':ids}, 
	            function(data){
			if(data.status == 1){
				$.messager.alert("提示信息",data.msg, 'info', function() {
					$('#dataShow').datagrid('load', getJSONParam());
					$('#dataShow').datagrid('getSelections').length=0;  //重设选中行
				
				});
			}else{
				$.messager.alert("提示信息", data.msg, 'error');
			}
		});	
	}

	
	function getSelectedIds(rows) {
		var ids = [];
		for (var i = 0; i < rows.length; i++) {
			ids.push(rows[i].id);
		}
		return  ids.join(',');
	}


</script>

</html>